# A set of types and utilities for analyzing collections of scheduling
# tracepoint events.

load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])  # Apache License 2.0

go_library(
    name = "sched",
    importpath = "github.com/google/schedviz/analysis/sched",

    srcs = [
        "sched_analysis.go",
        "sched_collection.go",
        "sched_collection_options.go",
        "sched_collection_queries.go",
        "sched_cpu_span_set.go",
        "sched_elementary_intervals.go",
        "sched_event_loader.go",
        "sched_event_loaders.go",
        "sched_metrics.go",
        "sched_per_cpu_events.go",
        "sched_query_filter.go",
        "sched_thread_inferrer.go",
        "sched_thread_span.go",
        "sched_thread_span_set.go",
        "sched_thread_transition.go",
        "sched_thread_transition_builder.go",
        "sched_types.go",
        "string_bank.go",
    ],
    deps = [
        ":event_loaders_go_proto",
        "//tracedata:schedviz_events_go_proto",
        "//tracedata:trace",
        "@com_github_golang_glog//:go_default_library",
        "@com_github_workiva_go-datastructures//augmentedtree:go_default_library",
        "@org_golang_google_grpc//codes:go_default_library",
        "@org_golang_google_grpc//status:go_default_library",
        "@org_golang_x_sync//errgroup:go_default_library",
    ],
)

go_test(
    name = "sched_test",
    size = "small",
    srcs = [
        "sched_analysis_test.go",
        "sched_collection_queries_test.go",
        "sched_cpu_span_set_test.go",
        "sched_elementary_intervals_test.go",
        "sched_event_loader_test.go",
        "sched_metrics_test.go",
        "sched_thread_inferrer_test.go",
        "sched_thread_span_set_test.go",
        "sched_thread_span_test.go",
        "sched_thread_transition_test.go",
        "string_bank_test.go",
    ],
    embed = [":sched"],
    deps = [
        ":event_loaders_go_proto",
        ":schedtestcommon",
        "//tracedata:eventsetbuilder",
        "//tracedata:schedviz_events_go_proto",
        "//tracedata:testeventsetbuilder",
        "//tracedata:trace",
        "@com_github_google_go-cmp//cmp:go_default_library",
    ],
)

go_library(
    name = "schedtestcommon",
    importpath = "github.com/google/schedviz/analysis/schedtestcommon",

    testonly = True,
    srcs = ["sched_test_common.go"],
    deps = [
        "//tracedata:eventsetbuilder",
        "//tracedata:schedviz_events_go_proto",
        "//tracedata:testeventsetbuilder",
    ],
)

go_test(
    name = "percpuevents_test",
    size = "small",
    srcs = [
        "sched_per_cpu_events_intervals_test.go",
        "sched_per_cpu_events_test.go",
    ],
    embed = [":sched"],
    deps = [
        ":schedtestcommon",
        "//tracedata:eventsetbuilder",
        "//tracedata:testeventsetbuilder",
        "//tracedata:trace",
        "@com_github_google_go-cmp//cmp:go_default_library",
        "@org_golang_google_grpc//codes:go_default_library",
        "@org_golang_google_grpc//status:go_default_library",
    ],
)

proto_library(
    name = "event_loaders_proto",
    srcs = ["sched_event_loaders.proto"],
    visibility = ["//visibility:public"],
)

go_proto_library(
    name = "event_loaders_go_proto",
    importpath = "github.com/google/schedviz/analysis/event_loaders_go_proto",

    proto = ":event_loaders_proto",
    visibility = ["//visibility:public"],
)
